package com.qf.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qf.pojo.DtsBrand;
import com.qf.pojo.DtsGrouponRules;
import com.qf.service.DtsAdminService;
import com.qf.service.DtsBrandService;
import com.qf.service.DtsCategoryService;
import com.qf.service.DtsGrouponRulesService;
import com.qf.util.ResponseUtil;
import com.qf.vo.CatVo;
import com.qf.vo.DtsBrandVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/admin/brand")
public class DtsAdminBrandController {
    @Autowired
    DtsBrandService brandService;
    @Autowired
    DtsCategoryService categoryService;
    @Autowired
    DtsAdminService adminService;

    @RequestMapping("/delete")
    public Object delete(@RequestBody DtsBrand dtsBrand){
        brandService.delete(dtsBrand);
        return ResponseUtil.ok();
    }

    @RequestMapping("/update")
    public Object update(@RequestBody DtsBrand dtsBrand){
        DtsBrand brand=brandService.update(dtsBrand);
        return ResponseUtil.ok(brand);
    }


    @RequestMapping("/create")
    public Object create(@RequestBody DtsBrand brand){
        DtsBrand dtsBrand=brandService.add(brand);
        return ResponseUtil.ok(dtsBrand);
    }




    @RequestMapping("/catAndAdmin")
    public Object catAndAdmin(){
        Map<String,Object> data = new HashMap<>();
        List<CatVo> catVoList = categoryService.findCat();
        List<Map<String,Object>> adminList=adminService.findAdmin();
        data.put("adminList",adminList);
        data.put("categoryList",catVoList);
        return ResponseUtil.ok(data);
    }





    @RequestMapping("/list")
    public Object listRecord(@RequestParam(name = "page",required = false,defaultValue = "1") Integer page,
                             @RequestParam(name = "limit",required = false,defaultValue = "10")Integer limit,
                             String sort, String order,Integer id,String name){

        IPage<DtsBrandVo> iPage=brandService.findByPage(page,limit,sort,order,id,name);
        Map<String,Object> data = new HashMap<>();
        data.put("total",iPage.getTotal());
        data.put("items",iPage.getRecords());
        return ResponseUtil.ok(data);

    }
}
